package me.realirea.api.event;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.BlockEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * 墓碑破坏事件
 */
public class TombstoneBreakEvent extends BlockEvent implements Cancellable {

    private static final HandlerList handlerList = new HandlerList();

    private final Player player;
    private final UUID deceased;
    private final long deathTime;
    private final List<ItemStack> funeral;
    private boolean cancelled;

    /**
     * 方块
     *
     * @param block     方块
     * @param player    玩家
     * @param deceased  死者
     * @param deathTime 死亡时间
     * @param funeral   陪葬品
     */
    public TombstoneBreakEvent(@NotNull Block block, Player player, UUID deceased, long deathTime, List<ItemStack> funeral) {
        super(block);
        this.player = player;
        this.deceased = deceased;
        this.deathTime = deathTime;
        this.funeral = funeral;
    }

    /**
     * 获取破坏的墓碑玩家
     *
     * @return 破坏墓碑的玩家
     */
    @NotNull
    public Player getPlayer() {
        return player;
    }

    /**
     * 获取死者死亡时间
     *
     * @return 死亡时间
     */
    @NotNull
    public Date getDeathTime() {
        return new Date(deathTime);
    }

    /**
     * 获取死者UUID
     *
     * @return 死者UUID
     */
    @NotNull
    public UUID getDeceasedUUID() {
        return deceased;
    }

    /**
     * 获取死者
     *
     * @return 死者
     */
    @NotNull
    public OfflinePlayer getDeceased() {
        return Bukkit.getOfflinePlayer(deceased);
    }

    /**
     * 获取陪葬品
     *
     * @return 陪葬品
     */
    @NotNull
    public List<ItemStack> getFuneral() {
        return funeral;
    }

    @Override
    public boolean isCancelled() {
        return cancelled;
    }

    @Override
    public void setCancelled(boolean cancelled) {
        this.cancelled = cancelled;
    }

    @NotNull
    @Override
    public HandlerList getHandlers() {
        return handlerList;
    }

    @NotNull
    public static HandlerList getHandlerList() {
        return handlerList;
    }
}
